<template>
	<view class="container">

		<!-- options 动画参数 -->
		<hx-lottie class="lottie" ref="lottieWeb" :options="reward" />

		<hx-lottie class="lottie" ref="lottieWeb" :options="gold" />

		<text class="text-logo">成语大富豪</text>

		<view class="content">
			<view class="box">
				<text class="text-title">{{title}}</text>

				<view class="text-desc-box">
					<text class="text-desc-top">{{desc}}</text>
					<text class="text-desc-bottom"></text>
				</view>

				<image :style="{ height: elementHeight }" class="image" src="" mode=""></image>

				<view class="button-box" @click="playpapers(downUrl)">
					{{button}}
				</view>

				<view class="down-load-desc" v-show="isShowTip">
					<view class="down-load-desc-content">
						<text>请转至浏览器下载</text> <text class="btn-copy" hover-class="button-hover" hover-start-time="20"
							hover-stay-time="70" @click="copyLink()">复制网址</text>
					</view>

				</view>

			</view>

		</view>

	</view>
</template>

<script>
	import clipboard from '@/js_sdk/clipboard.js';

	import {
		Base64
	} from '@/js_sdk/js-base64/base64.min.js';

	export default {
		data() {
			return {
				reward: {
					autoplay: true,
					data: require("../../static/reward.json")
				},
				gold: {
					autoplay: true,
					data: require("../../static/gold.json")
				},
				botton: {
					autoplay: true,
					data: require("../../static/button.json")
				},
				elementHeight: '50vh',
				title: "新用户  注册送好礼",
				desc: "顶包无上限，提现秒到账",
				button: "下载立刻赚钱",
				isShowTip: true,
				downUrl: ""
			}
		},
		onLoad(option) {

			// #ifdef H5
			let ua = window.navigator.userAgent.toLowerCase()
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				// do something
				this.isShowTip = true;
			} else {
				this.isShowTip = false;
			}

			if (this.isBase64Encoded(option.link)) {
				this.downUrl = Base64.decode(option.link);
			}

			// #endif

		},
		methods: {
			isBase64Encoded(str) {
				try {
					return btoa(atob(str)) === str;
				} catch (error) {
					return false;
				}
			},
			playpapers(url) {

				// #ifdef H5
				let ua = window.navigator.userAgent.toLowerCase()
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					// do something
					this.copyLink();
					let that = this;
					uni.showToast({
						title: "网址已复制，请到浏览器下载",
						duration: 3000,
						icon: "none"
					});

				} else {
					let dload = document.createElement("a");

					dload.download = ''; // 设置下载的文件名，默认是'下载'

					dload.href = url;

					document.body.appendChild(dload);

					dload.click();

					dload.remove(); // 下载之后把创建的元素删除

					uni.showToast({

						title: "请点击普通下载",
						duration: 3000,
						icon: "loading"

					});
				}
				// #endif


			},
			copyLink() {

				uni.setClipboardData({
					data: location.href,
					success: function() {
						// 重点~做笔记
						uni.showToast({
							title: '网址已复制',
							duration: 2500,
							icon: 'none'
						});

					},
					fail: function(err) {
						uni.showToast({
							title: '复制失败',
							duration: 2500,
							icon: 'none'
						});
					}
				})

			}
		},

	}
</script>

<style lang="scss" scoped>
	.container {
		position: relative;
		left: 0;
		top: 0;
		width: 100%;
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;


		&::before {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background: linear-gradient(45deg, #EFDBC7, #E1C4FC, #CBF2DC, #EFDBC7);
			// background: linear-gradient(45deg, #F6E9D9, #ff00ff, #00ffff);
			background-size: 300% 300%;
			z-index: 0;
			animation: flow 10s infinite linear;
		}

		@keyframes flow {
			0% {
				background-position: 0 50%;
			}

			100% {
				background-position: 100% 50%;
			}
		}


		.lottie,
		.text-logo {
			position: absolute;
			left: 0;
			top: 0;
		}

		.text-logo {
			padding: 10rpx 20rpx;
			font-size: 26rpx;
			font-weight: bold;
			border-bottom-right-radius: 10px;
			background-color: white;

			&::before {
				content: "";
				display: inline-block;
				vertical-align: middle;
				width: 1em;
				height: 1em;
				margin-right: 10rpx;
				padding-bottom: 6rpx;
				background-image: url(../../static/logo.png);
				background-size: contain;
				background-repeat: no-repeat;
			}
		}

		.content {
			// 此处将布局悬浮在背景之上
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: transparent;

			// 让子元素居中
			display: flex;
			justify-content: center;
			align-items: center;

			.box {
				padding: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.text-title {
					display: inline-block;
					color: black;
					font-size: 60rpx;
					font-weight: bold;
					padding-bottom: 80rpx;
				}

				.text-desc-box {
					position: relative;
					width: 100%;

					.text-desc-bottom {
						position: absolute;
						top: 10%;
						left: -10%;
						width: 80%;
						padding: 40rpx 100rpx;
						background-image: url("@/static/text_bg.png");
						background-position: center -0rpx;
						background-repeat: no-repeat;
						background-size: cover;
						z-index: 1;
					}

					.text-desc-top {
						position: absolute;
						top: 0%;
						left: -20%;
						width: 100%;
						font-weight: bold;
						padding: 30rpx 100rpx;
						text-align: center;
						color: white;
						font-size: 30rpx;
						letter-spacing: 3px;
						z-index: 2;
					}

				}



				.image {
					display: inline-block;
					width: 80%;
				}


				.button-box {
					display: inline-block;
					padding: 30rpx 60rpx;
					margin-top: 60rpx;
					border-radius: 26px;
					color: block;
					font-weight: bold;
					text-align: center;
					font-family: Helvetica;
					font-size: 36rpx;
					cursor: pointer;
					letter-spacing: 6px;
					animation: pulse 1.5s infinite;
					transition: transform 0.3s;
					position: relative;
					box-sizing: border-box;
					background: linear-gradient(-75deg, yellow, orange, yellow, orange, yellow);
					// background: linear-gradient(90deg, yellow, #f441a5, #ffeb3b, yellow);
					background-size: 400%;
					animation: gradient 20s linear infinite;

					&:hover {
						transform: scale(1.1);
					}

					&::hover:before {
						/* 悬停时显示阴影 */
						opacity: 1;
					}

					@keyframes pulse {
						0% {
							transform: scale(1);
						}

						50% {
							transform: scale(1.2);
						}

						100% {
							transform: scale(1);
						}
					}

					@keyframes gradient {
						0% {
							background-position: 600%;
						}

						100% {
							background-position: 0%;
						}
					}

				}

				.down-load-desc {
					display: flex;
					margin-top: 36rpx;
					align-items: center;
					justify-content: center;

					.down-load-desc-content {
						display: flex;
						color: white;
						align-items: center;
						justify-content: center;

						.btn-copy {
							margin-left: 20rpx;
							color: #5500ff;
						}
					}

				}

			}

		}
	}
</style>